package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.FarmingRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 农事记录DAO
 */
@Repository
public class FarmingRecordDao extends BaseDao<FarmingRecord> {
    
    @Override
    protected String getFileName() {
        return "farming_records.json";
    }
    
    @Override
    protected TypeReference<List<FarmingRecord>> getTypeReference() {
        return new TypeReference<List<FarmingRecord>>() {};
    }
    
    @Override
    protected Long getId(FarmingRecord entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(FarmingRecord entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据地块ID查询
     */
    public List<FarmingRecord> findByFieldId(Long fieldId) {
        return findAll().stream()
            .filter(record -> fieldId.equals(record.getFieldId()))
            .toList();
    }
    
    /**
     * 根据农事类型查询
     */
    public List<FarmingRecord> findByFarmingType(String farmingType) {
        return findAll().stream()
            .filter(record -> farmingType.equals(record.getFarmingType()))
            .toList();
    }
}

